<template>
  <van-row class="main-menu">
    <van-nav-bar left-text="返回" title="单位看板" @click-left="doBack"/>
    <van-empty v-if="showEmpty" description="无分析数据" />
    <van-row>
        <div id="barfordwkhbm" style="width:100%;height:450px;padding 10px 0px"></div>
    </van-row>
  </van-row>
</template>

<script>
import { getDeptGradeAnalysis } from '@/api/analysis'

const echarts = require('echarts')
export default {
  name: 'DeptGradeAnalysis',
  data () {
    return {
      echarts: null,
      options: null,
      showEmpty: false,
      condition: {
        department_path: ''
      },
      bmmcOptions: null
    }
  },
  mounted () {
    this.echarts = echarts.init(document.getElementById('barfordwkhbm'))
    this.options = {
      title: {
        show: true,
        text: '单位自评评分情况'
      },
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'shadow'
        }
      },
      legend: {
        data: ['扣分', '加分']
      },
      grid: {
        containLabel: true
      },
      xAxis: {
        type: 'value',
        show: true
      },
      yAxis: {
        type: 'category',
        data: []
      },
      series: [
        {
          name: '扣分',
          type: 'bar',
          stack: '总量',
          label: {
            show: true
          },
          data: []
        },
        {
          name: '加分',
          type: 'bar',
          stack: '总量',
          label: {
            show: true
          },
          data: []
        }
      ]
    }
    this.condition.department_path = this.$store.state.authInfo.currentDept.department_path
    console.log(this.$store.state.authInfo.currentDept)
    this.doGetDeptGradeAnalysis()
  },
  methods: {
    doBack () {
      // this.$store.commit('authInfo/delCurrentDept')
      this.$router.back()
    },
    doGetDeptGradeAnalysis () {
      getDeptGradeAnalysis(this.condition).then(res => {
        let { data } = res
        if (data[this.$response.CODE] === this.$response.SUCCESS) {
          let listData = data[this.$response.DATA] ? data[this.$response.DATA] : []
          if (listData.length > 0) {
            for (let i = 0; i < listData.length; i++) {
              this.options.yAxis.data[i] = listData[i].bmmc
              this.options.series[0].data[i] = listData[i].totalscore.toFixed(3)
              this.options.series[1].data[i] = listData[i].addscore.toFixed(3)
            }

            this.echarts.setOption(this.options)
          }
          this.showEmpty = listData.length === 0
        } else {
          this.$toast.fail('获取数据失败：' + data[this.$response.MESSAGE])
        }
      }, errFunc => {
        this.$notify('服务调用失败：' + errFunc.toString())
        console.log(errFunc.toString())
      })
    }
  }
}
</script>

<style scoped lang="less">

</style>
